<?PHP

class mvPDOStatement extends PDOStatement{

	/**
	* row count
	* @access private
	* @var	integer
	*/
	private $mysqlnumrows = null;

	private function __construct(){
		$this->setFetchMode(PDO::FETCH_ASSOC);
	}

	/**
	* Extends the execute function so that it will run the found rows directive if needed
	*
	* @access	public
	* @param	array	list of arguments
	* @param	bool	Suppress errors
	* @return	object	results object
	*/
	public function execute($aParams = array(), $supress_error = false) {
		$results = parent :: execute($aParams);
		if($results){
			stripos(strtolower($this->queryString), 'sql_calc_found_rows') ? $this->mysqlnumrows = $this->get_mysql_num_rows() : $this->mysqlnumrows = false;
		}elseif(!$supress_error){
			mvError::sqlError('Error Executing Query', $this->queryString, $aParams, print_r($this->errorInfo(), true));
			return false;
		}else{
			return false;
		}
		return $results;
	}

	/**
	* provides the found rows value for queries containing the appropriate things
	*
	* @access	private
	* @return	integer	results count
	*/
	private function get_mysql_num_rows(){
		$sql 	= 'SELECT FOUND_ROWS() AS cnt';
		$query 	= $GLOBALS['db']->prepare_execute($sql);

		$row 	= $query->fetch();

		return $row['cnt'];
	}

	/**
	* Extends the execute function so that it will run the found rows directive if needed
	*
	* @access	public
	* @return	integer	the number of mysql rows returned
	* @TODO calculate rows returned for regular queries
	*/
	public function mysql_num_rows(){
		return $this->mysqlnumrows;
	}
}

?>